.TH std::basic_string_view::contains 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::basic_string_view::contains \- std::basic_string_view::contains

.SH Synopsis
   constexpr bool contains( basic_string_view sv ) const noexcept; \fB(1)\fP (since C++23)
   constexpr bool contains( CharT c ) const noexcept;              \fB(2)\fP (since C++23)
   constexpr bool contains( const CharT* s ) const;                \fB(3)\fP (since C++23)

   Checks if the string view contains the given substring, where

   1) the substring is a string view.
   2) the substring is a single character.
   3) the substring is a null-terminated character string.

   All three overloads are equivalent to return find(x) != npos;, where x is the
   parameter.

.SH Parameters

   sv - a string view
   c  - a single character
   s  - a null-terminated character string

.SH Return value

   true if the string view contains the provided substring, false otherwise.

.SH Notes

      Feature-test macro      Value    Std        Feature
   __cpp_lib_string_contains 202011L (C++23) contains functions

.SH Example


// Run this code

 #include <string_view>
 using namespace std::literals;

 static_assert
 (
     // bool contains(basic_string_view x) const noexcept;
     "https://cppreference.com"sv.contains("cpp"sv) == true and
     "https://cppreference.com"sv.contains("php"sv) == false and

     // bool contains(CharT x) const noexcept;
     "C++23"sv.contains('+') == true and
     "C++23"sv.contains('-') == false and

     // bool contains(const CharT* x) const;
     std::string_view("basic_string_view").contains("string") == true and
     std::string_view("basic_string_view").contains("String") == false
 );

 int main() {}

.SH See also

   starts_with checks if the string view starts with the given prefix
   (C++20)     \fI(public member function)\fP
   ends_with   checks if the string view ends with the given suffix
   (C++20)     \fI(public member function)\fP
   find        find characters in the view
               \fI(public member function)\fP
   substr      returns a substring
               \fI(public member function)\fP
   contains    checks if the string contains the given substring or character
   (C++23)     \fI(public member function of std::basic_string<CharT,Traits,Allocator>)\fP

